# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=rust

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9
pkgrel=1
pkgdesc="A safe, concurrent, practical language from Mozilla (mingw-w64)"
arch=('any')
url="http://www.rust-lang.org/"
license=('custom:MIT' 'Apache')
#depends=('shared-mime-info')
makedepends=('git'
      "${MINGW_PACKAGE_PREFIX}-gcc"
      "${MINGW_PACKAGE_PREFIX}-llvm"
      'curl'
      "${MINGW_PACKAGE_PREFIX}-libffi"
      'python2'
      )
options=('!makeflags' 'staticlibs')
#install=rust.install
source=(http://static.rust-lang.org/dist/rust-${pkgver}.tar.gz
    add-libffi-to-link.patch)
md5sums=('0c38a99666e0a13d4617a06e1d44b8da'
         '9fa3227f99947d14c773ea0804736efa')

prepare() {
  cd ${srcdir}/${_realname}-$pkgver
  sed -e "s|CFG_WINDOWSY_\$(1)|0|g" -i mk/rustllvm.mk
  patch -p1 -i ${srcdir}/add-libffi-to-link.patch
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  #export CFG_LLVM_ROOT=${MINGW_PREFIX}
  cd "${srcdir}/build-${MINGW_CHOST}"
    ../${_realname}-$pkgver/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --llvm-root=${MINGW_PREFIX}
    
    #--enable-local-rust              use an installed rustc rather than downloading a snapshot
    #--local-rust-root=[/usr/local]   set prefix for local rust binary
    #--enable-clang                   prefer clang to gcc for building the runtime

    make VERBOSE=1
}

package() {
    cd "${srcdir}/build-${MINGW_CHOST}"
    make DESTDIR=${pkgdir} install
}
